package com.ego.member.controller;

import java.util.Arrays;
import java.util.List;

import com.ego.common.vo.PageVo;
import com.ego.member.vo.MemberLevelSearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ego.member.po.MemberLevel;
import com.ego.member.service.MemberLevelService;
import com.ego.common.util.Result;

import javax.validation.Valid;

/**
 * @program: ego
 * @description 会员等级控制器
 * @author KamTang
 * @date 2022-11-13 13:28:12
 */
@RestController
@RequestMapping("member/level")
public class MemberLevelController {

    @Autowired
    private MemberLevelService memberLevelService;

    @PostMapping("/search")
    public Result search(@Valid @RequestBody MemberLevelSearchVo search) {
        PageVo<MemberLevel> page = memberLevelService.search(search);
        return Result.ok().put("page", page);
    }

    @GetMapping("/list")
    public Result list() {
        List<MemberLevel> list = memberLevelService.list();
        return Result.ok().put("list", list);
    }

    /**
     * 信息
     */
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Long id){
		MemberLevel memberLevel = memberLevelService.getById(id);
        return Result.ok().put("memberLevel", memberLevel);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@RequestBody MemberLevel memberLevel){
		memberLevelService.save(memberLevel);
        return Result.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public Result update(@RequestBody MemberLevel memberLevel){
		memberLevelService.updateById(memberLevel);
        return Result.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
		memberLevelService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
